package com.ly.datacenter.jdbc.util;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * function：
 * @author watson  email: watson.wu@hotmail.com
 * @date 2009-9-4
 */
public class ResultSetParserUtils {

	/**
	 * function:
	 * @param rs
	 * @param column
	 * @param string
	 * @return
	 */
	public static Object getValue(ResultSet rs, int columnIndex,
			String columnTypeName) {
		try {
			if("BIT".equalsIgnoreCase(columnTypeName)) {
				return rs.getBoolean(columnIndex);
			} else if("TINYINT".equalsIgnoreCase(columnTypeName)) {
				return rs.getByte(columnIndex);
			} else if("SMALLINT".equalsIgnoreCase(columnTypeName)) {
				return rs.getShort(columnIndex);
			} else if("INTEGER".equalsIgnoreCase(columnTypeName)) {
				return rs.getInt(columnIndex);
			} else if("BIGINT".equalsIgnoreCase(columnTypeName)) {
				return rs.getLong(columnIndex);
			} else if("FLOAT".equalsIgnoreCase(columnTypeName)) {
				return rs.getFloat(columnIndex);
			} else if("REAL".equalsIgnoreCase(columnTypeName)) {
				return rs.getFloat(columnIndex);
			} else if("DOUBLE".equalsIgnoreCase(columnTypeName)) {
				return rs.getDouble(columnIndex);
			} else if("NUMERIC".equalsIgnoreCase(columnTypeName)) {
				return rs.getBigDecimal(columnIndex);
			} else if("CHAR".equalsIgnoreCase(columnTypeName)) {
				return rs.getString(columnIndex);
			} else if("VARCHAR".equalsIgnoreCase(columnTypeName)) {
				return rs.getString(columnIndex);
			} else if("LONGVARCHAR".equalsIgnoreCase(columnTypeName)) {
				return rs.getString(columnIndex);
			} else if("DATE".equalsIgnoreCase(columnTypeName)) {
				return rs.getDate(columnIndex);
			} else if("TIME".equalsIgnoreCase(columnTypeName)) {
				return rs.getTime(columnIndex);
			} else if("TIMESTAMP".equalsIgnoreCase(columnTypeName)) {
				return rs.getTimestamp(columnIndex);
			} else if("BINARY".equalsIgnoreCase(columnTypeName)) {
				return rs.getBytes(columnIndex);
			} else if("VARBINARY".equalsIgnoreCase(columnTypeName)) {
				return rs.getBytes(columnIndex);
			} else if("LONGVARBINARY".equalsIgnoreCase(columnTypeName)) {
				return rs.getBytes(columnIndex);
			} else
				return null;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		return null;
	}

}

